﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net.Sockets;
using HammerMUD.Accounts;

namespace HammerMUD.System
{
    public class User
    {
        private StreamReader reader;
        private StreamWriter writer;
        private Socket socket;
        private UserState currentState;
        private Account userAccount;

        public UserState CurrentState
        {
            get { return currentState; }
            set { currentState = value; }
        }

        public Account UserAccount
        {
            get { return userAccount; }
            set { userAccount = value; }
        }

        public User()
        {
        }

        public User(StreamWriter writer, StreamReader reader, Socket socket)
        {
            this.reader = reader;
            this.writer = writer;
            this.socket = socket;
            this.currentState = new UserState();
            this.userAccount = null;
        }

        public void Flush()
        {
            writer.Flush();
        }

        public String Read()
        {
            try
            {
                return reader.ReadLine();
            }
            catch
            {
                return String.Empty;
            }
        }

        public void Close()
        {
            currentState = new UserState();
            this.userAccount = null;
            reader.Close();
            writer.Close();
            socket.Close();
        }

        public void Send(String message)
        {
            try
            {
                writer.WriteLine(message);
            }
            catch
            {
            }
        }

        public void Prompt(String message)
        {
            try
            {
                writer.Write(message);
            }
            catch
            {
            }
        }
    }
}
